//
//  WHMainViewController.swift
//  WHWeiBo
//
//  Created by wangchen on 17/3/28.
//  Copyright © 2017年 王晨. All rights reserved.
//

import UIKit

class WHMainViewController: UITabBarController {

    override func viewDidLoad() {
        super.viewDidLoad()

//        self.addChildViewController(<#T##childController: UIViewController##UIViewController#>)
        
        
        
        //使用KVC给只读属性赋值
        let whtabbar = WHTabBar()
        
        self.setValue(whtabbar, forKey:"tabBar")
        
        
        //添加首页控制器
        addChildViewController(childController: WHHomeController(), imageName: "tabbar_home", title: "首页")
        addChildViewController(childController: WHMessageController(), imageName: "tabbar_message_center", title: "消息")
        addChildViewController(childController: WHDiscoverController(), imageName: "tabbar_discover", title: "发现")
        addChildViewController(childController: WHMineController(), imageName: "tabbar_profile", title: "我的")
    }
    
    
    
    
    
    func addChildViewController(childController: UIViewController, imageName: String, title: String) {
        
        childController.tabBarItem.image = UIImage(named: imageName)
        childController.tabBarItem.selectedImage = UIImage(named: imageName + "_selected")?.withRenderingMode(.alwaysOriginal)
        childController.tabBarItem.setTitleTextAttributes([NSForegroundColorAttributeName: UIColor.orange], for: .selected)
        childController.tabBarItem.setTitleTextAttributes([NSFontAttributeName : UIFont.systemFont(ofSize: 12)], for: .normal)
//        childController.tabBarItem.title = title
//        childController.navigationItem.title = title
        childController.title = title
        //创建导航视图控制器
        let nav = UINavigationController(rootViewController: childController)
        //添加子视图控制器
        addChildViewController(nav)
        
    }
}
